/**
 * Created by cx on 2018/12/21.
 *  modify by zhaoxiaoqi : 支持一级、二级、三级菜单
 */
// 动态添加路由配置项
export const mergedData = function (jsonDatas) {
  let routerDatas = {
    path: "/homeIndex",
    name: "homeIndex",
    component: require("@/page/home/homeIndex").default,
    redirect: "/home",
    children: [
      {
        path: "/home",
        name: "home",
        component: require("@/page/home/home").default,
      },
    ],
  };
  if (jsonDatas) {
    for (let i = 0; i < jsonDatas.length; i++) {
      if (jsonDatas[i].asChildren) {
        let children = jsonDatas[i].children;
        let pageHomeName = jsonDatas[i].pageHomeName;
        // console.log(jsonDatas);
        let datas = {
          path: jsonDatas[i].indexPath,
          name: jsonDatas[i].pageHomeName,
          component:
            require(`@/page/${jsonDatas[i].pageHomeName}${jsonDatas[i].indexPath}`)
              .default,
          children: [],
        };
        for (let j = 0; j < children.length; j++) {
          if (children[j].asChildren) {
            // console.log(children);
            let subChildren = children[j].children;
            for (let k = 0; k < subChildren.length; k++) {
              let temp = {
                path: subChildren[k].indexPath,
                name: subChildren[k].name,
                component:
                  require(`@/page/${subChildren[k].pageFileName}/${subChildren[k].component}`)
                    .default,
              };
              // console.log(
              //   subChildren[k].pageFileName,
              //   subChildren[k].component
              // );
              datas.children.push(temp);
            }
            routerDatas.children.push(datas);
          } else {
            // console.log(children);
            let temp = {
              path: children[j].indexPath,
              name: children[j].name,
              component:
                require(`@/page/${children[j].pageFileName}/${children[j].component}`)
                  .default,
            };
            datas.children.push(temp);
            routerDatas.children.push(datas);
          }
        }
      } else {
        // let temp = {
        //   path: jsonDatas[i].path,
        //   name: jsonDatas[i].name,
        //   meta: {
        //     title: jsonDatas[i].title,
        //     // parentName:""
        //   },
        //   component: (resolve) =>
        //     require([
        //       `@/page/${jsonDatas[i].pageFileName}/${jsonDatas[i].component}.vue`,
        //     ], resolve),
        // };
        // routerDatas.children.push(temp);
      }
    }
  }
  return routerDatas;
};
